package reflect;

import java.io.File;
import java.lang.reflect.Field;

public class ReflectDemo10 {
    public static void main(String[] args) throws Exception {
        // 暴力反射字符串，破坏其逻辑
        String s1 ="123abc";
        String s2 = "123abc";
        System.out.println("s1:" + s1);
        System.out.println("s2:" + s2);

        Class cls = String.class;// Class.forName("java.lang.String");
        Field field = cls.getDeclaredField("value");

        field.setAccessible(true);
        char[] chars = (char[]) field.get(s1); // char[] chars = s1.value;
        // 上面的语法都在java9中才适用
        chars = new char[]{'h','e','l','l','o'};
        field.set(s1,chars);
        field.setAccessible(false);
        System.out.println("s1:" +s1);
        System.out.println("s2:" + s2);


        String s3 = "123abc";
        System.out.println("s3:"+s3);//s3:hello

    }
}
